package top.littleze.aiattendance.utils.page;

import java.io.Serializable;

/**
 * @Author ZhaoGengze
 * @Date 2021/7/3 13:25
 */

public class Reply<T> implements Serializable {
    private boolean success;
    private Integer code;
    private String msg;
    private Integer count;
    private T data;

    public Reply() {
    }

    public boolean hasErrors() {
        return !this.success;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Integer getCount() {
        return this.count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }


    public static <T> Reply<T> failure(String msg) {
        return failure(9999, msg);
    }


    public static <T> Reply<T> failure(Integer code, String msg) {
        Reply reply = new Reply();
        reply.setSuccess(false);
        reply.setMsg(msg);
        reply.setCode(code);
        return reply;
    }

    public static Reply<Void> failuer(int code, String msg) {
        Reply reply = new Reply();
        reply.setCode(code);
        reply.setMsg(msg);
        return reply;
    }


    public static Reply<Void> success() {
        Reply reply = new Reply();
        reply.setSuccess(true);
        reply.setCode(0);
        reply.setMsg("");
        return reply;
    }


    public static <T> Reply<T> success(int code) {
        Reply reply = new Reply();
        reply.setSuccess(true);
        reply.setCode(code);
        reply.setMsg("");
        reply.setData(null);
        return reply;
    }

    public static <T> Reply<T> success(T data) {
        Reply reply = new Reply();
        reply.setSuccess(true);
        reply.setCode(0);
        reply.setMsg("");
        reply.setData(data);
        return reply;
    }

    public static <T> Reply<T> success(String msg) {
        Reply reply = new Reply();
        reply.setSuccess(true);
        reply.setCode(0);
        reply.setMsg(msg);
        return reply;
    }

    public static Reply<Void> success(int code, String msg) {
        Reply reply = new Reply();
        reply.setSuccess(true);
        reply.setCode(code);
        reply.setMsg(msg);
        return reply;
    }

    public static <T> Reply<T> success(T data, int count) {
        Reply reply = new Reply();
        reply.setSuccess(true);
        reply.setCode(0);
        reply.setMsg("");
        reply.setCount(count);
        reply.setData(data);
        return reply;
    }
}

